﻿using Application.DictTypeService;
using AutoMapper;
using Domain.Entity;
using Domain.Entity.bs;
using Domain.Entity.sys;
using Domain.IRepository;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Application.ProductTypeService
{
    public class ProductTypeService : IProductTypeService
    {
        private readonly IProductTypeRepository productTypeRepository;
        private readonly IMapper mapper;

        public ProductTypeService(IProductTypeRepository productTypeRepository,IMapper mapper)
        {
            this.productTypeRepository = productTypeRepository;
            this.mapper = mapper;
        }

        //添加货品类型
        public async Task<int> AddProductType(AddProductTypeDto addProductTypeDto)
        {
            //转换
            ProductType productType = mapper.Map<ProductType>(addProductTypeDto);
            return await productTypeRepository.AddProductType(productType);
        }

        //删除货品类型
        public async Task<int> DeleteProductType(int id)
        {
            return await productTypeRepository.DeleteProductType(id);
        }


        //查询所有货品类型
        public async Task<List<ProductType>> GetAllProductTypes()
        {
            return await productTypeRepository.GetAllProductTypes();
        }

        //分页查询货品类型
        public async Task<FenYe<ProductType>> GetProductType(FenYe<ProductType> fenYe, string? name, int? status, string? createname, string? starttime, string? endtime)
        {
            return await productTypeRepository.GetProductType(fenYe, name, status, createname, starttime, endtime);
        }

        //根据id查询货品类型
        public async Task<ProductType> GetProductTypeById(int id)
        {
            return await productTypeRepository.GetProductTypeById(id);
        }

        //修改货品类型
        public async Task<int> UpdateProductType(UpdateProductTypeDto updateProductTypeDto)
        {
            //转换
            ProductType productType = mapper.Map<ProductType>(updateProductTypeDto);
            return await productTypeRepository.UpdateProductType(productType);
        }
    }
}
